package com.leetcode.partition10;

/**
 * @author `RKC`
 * @date 2021/12/19 9:14
 */
public class LC997找到小镇的法官 {

    public int findJudge(int n, int[][] trust) {
        int[] inDegree = new int[n + 1], outDegree = new int[n + 1];
        for (int[] edge : trust) {
            inDegree[edge[1]]++;
            outDegree[edge[0]]++;
        }
        for (int i = 1; i <= n; i++) {
            if (inDegree[i] == n - 1 && outDegree[i] == 0) return i;
        }
        return -1;
    }
}
